package org.shijiagen.carousel.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import org.shijiagen.carousel.mapper.CarouselMapper;
import org.shijiagen.carousel.service.CarouselService;
import org.shijiagen.pojo.Carousel;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class CarouselServiceImpl implements CarouselService {

    private final CarouselMapper carouselMapper;

    @Override
    @Cacheable(value = "list.carousel", key = "#root.methodName", cacheManager = "cacheManagerDay")
    public List<Carousel> list() {
        List<Carousel> result = carouselMapper.selectList(new QueryWrapper<Carousel>().orderByDesc("priority"));
        return result.stream().limit(6).collect(Collectors.toList());
    }
}
